Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
event listener attached to canvas only receives {"isTrusted":true} object in codeSandbox
canvas.onmousedown = function (event) {
  console.log(JSON.stringify(event)); // this logs {"isTrusted":true} 
};

same width

canvas.addEventListener("mousedown",  function (event) {
  console.log(JSON.stringify(event)); // this logs {"isTrusted":true} 
});

and when I try to log just the eventwithout parsing it the app crashes

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That sandbox has a lot of code, I'm just going to focus on what you have here...

The mouse event object is complex and most likely JSON.stringify is taking a shortcut; and correct if you try to output the entire object it will be slow or it could crash like you describe, but there are other properties there, you can see it on the sample below.

var canvas = document.querySelector("canvas")
var ctx = canvas.getContext("2d")
ctx.fillStyle = "red"

for (let i = 10; i < 100; i += 10 )
  ctx.rect(i, i, 50, 50);
ctx.stroke();

canvas.onmousedown = function (event) {
  console.log(JSON.stringify(event));
  console.log(event.x, event.y);
  
  ctx.beginPath()
  ctx.arc(event.x, event.y, 5, 0, 8)
  ctx.fill();
};
body { margin: 0 }
<canvas id="canvas"></canvas>

You can see there I'm using event.x, event.y to draw circles at the point the user clicked.

You can read more about the available properties on the official documentation:
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent#properties


I imagine that your end goal is not to just output:
console.log(JSON.stringify(event)) there more must be something else you need those events to do...

Maybe best to ask a new question...
Explain there what are you trying to do in those events and what error are you getting if any.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda